package edu.nf.vrs.admin.advice;

import edu.nf.reservation.exception.ReservationException;
import edu.nf.vrs.admin.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Lv
 * @date 2022/4/2
 * 全局异常处理
 */
@ControllerAdvice(basePackages = "edu.nf.vrs.admin.controller")
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public @ResponseBody ResultVO handlerDataAccesException(RuntimeException e){
        log.info(e.getMessage());
        return response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "异常服务，请稍后重试");
    }

    public ResultVO response(int code,String message){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        vo.setMessage(message);
        return vo;
    }
}
